# coding: UTF-8

def display():
    print("+---+---+---+")
    cell_line = "|"
    for i in range(9):
        cell_line += " " + cells[i].getmark() + " |"        # メソッド呼び出しに変更
        if i % 3 == 2:
            print(cell_line)
            cell_line = "|"
            print("+---+---+---+")

def mark(num):
    if num % 2:
        return "X"
    else:
        return "O"

LINES = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))

def is_lined(cells):
    for current in LINES:
        if (cells[current[0]].getmark() == "O" and cells[current[1]].getmark() == "O" and cells[current[2]].getmark() == "O") or \
           (cells[current[0]].getmark() == "X" and cells[current[1]].getmark() == "X" and cells[current[2]].getmark() == "X"):      # メソッド呼び出しに変更
            return True
    return False

class Cell(object):
    def __init__(self):
        self.mark = " "
    
    def set(self, mark):
        self.mark = mark
    
    def getmark(self):
        return self.mark
    
    def is_empty(self):
        return self.mark == " "

if __name__ == '__main__':
    cells = [Cell() for i in range(9)]
    count = 0
    while count < 9 and not is_lined(cells):
        row = input("Rows? : ")
        if row not in(1,2,3):
            print("Input 1, 2 or 3.")
            continue
        
        column = input("Column? : ")
        if column not in(1,2,3):
            print("Input 1, 2 or 3.")
            continue
        
        target_cell = cells[(row - 1) * 3 + (column - 1)]
        if target_cell.is_empty():          # メソッド呼び出しに変更
            target_cell.set(mark(count))    # メソッド呼び出しに変更
        else:
            print("Not empty. Try another.")
            continue
        display()
        count += 1
    
    if is_lined(cells):
        print("Game over. " + mark(count - 1) + " won.")
    else:
        print("Game over. Draw.")
